package com.aiyige.trace.util;

import com.aiyige.trace.model.Trace;

import java.util.Stack;

public class TraceUtil {
    private static Stack<Trace> stack = new Stack<>();

    public static void push(Trace trace) {
        stack.push(trace);
    }

    public static Trace pop() {
        try {
            Trace trace = stack.pop();
            if (stack.size() <= 1) {
                stack.clear();
            }
            return trace;
        } catch (Exception e) {
            return null;
        }
    }

    public static Trace peek() {
        try {
            return stack.peek();
        } catch (Exception e) {
            return null;
        }
    }

    public static boolean empty() {
        return stack.empty();
    }

    public static int size() {
        return stack.size();
    }

    public static void clear() {
        stack.clear();
    }
}
